package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPager_AllPlayAdapter;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentAllPlayHottest;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentAllPlayMyPublish;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentAllPlayNewest;
import liumengbaio.lolzhangyoubao.Activity.InFo.FreeHeroInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/10.
 */

public class AllPlayActivity extends AppCompatActivity {
    private TabLayout tablayoutallplay;
    private ViewPager viewPagerallplay;
    private List<String> tabNames;
    private List<Fragment> fragments;
    private ViewPager_AllPlayAdapter allPlayAdapter;
    private TextView tv_allplay;
    private Button btn_return;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_allplay);
        initView();
        initData();
        initEvent();

    }


    private void initView() {
      tablayoutallplay= (TabLayout) findViewById(R.id.tab_all_play);
        viewPagerallplay= (ViewPager)findViewById(R.id.allplay_viewpage);
        tv_allplay= (TextView)findViewById(R.id.tv_allplay);
        btn_return= (Button) findViewById(R.id.btn_allplay_return);


    }

    private void initData() {
     tabNames=new ArrayList<>();
        tabNames.add("最新");
        tabNames.add("最热");
        tabNames.add("我的发布");
        fragments=new ArrayList<>();
        FreeHeroInfo info = (FreeHeroInfo) getIntent().getSerializableExtra("playerinfo");
        FragmentAllPlayNewest fragmentAllPlayNewest =FragmentAllPlayNewest.newInstants(info);
        fragments.add(fragmentAllPlayNewest);
        FragmentAllPlayHottest fragmentAllPlayHottest =FragmentAllPlayHottest.newInstants(info);
        fragments.add(fragmentAllPlayHottest);
        FragmentAllPlayMyPublish fragmentAllPlayMyPublish=FragmentAllPlayMyPublish.newInstants(info);
        fragments.add(fragmentAllPlayMyPublish);
        allPlayAdapter =new ViewPager_AllPlayAdapter(getSupportFragmentManager(),tabNames,fragments);
        viewPagerallplay.setAdapter(allPlayAdapter);
        tablayoutallplay.setupWithViewPager(viewPagerallplay);

    }
    private void initEvent() {
        FreeHeroInfo allplayinfo = (FreeHeroInfo) getIntent().getSerializableExtra("playerinfo");
        tv_allplay.setText(allplayinfo.getName()+"-玩家玩法发布");
        btn_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }



}
